﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.IO;

namespace SampleTree
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            showTree("4MAL000001");
        }

        private void showTree(string id)
        {

            string cn = "Server = localhost; Database = NewBiz; Trusted_Connection = True;";
            string streeContent = (new Member(cn)).GetGeneologyTable(id);

            string sTreeTemplate = Application.StartupPath + @"\tree.htm";

            string sFile = Application.StartupPath + @"\" + id + ".htm";
            if (File.Exists(sFile)) File.Delete(sFile);
            string s;
            using (StreamReader sr = new StreamReader(sTreeTemplate))
            {
                s = sr.ReadToEnd();
                s = s.Replace("<@@treetbl@@>", streeContent);
            }

            using (StreamWriter outfile = new StreamWriter(sFile))
            {
                outfile.Write(s);
            }

            webBrowser1.Navigate(sFile);
        }
    }
}
